package surfing.chatting.ui.label;

import java.awt.AlphaComposite;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class LabelImage  extends JLabel {
	private static final long serialVersionUID = 1L;

		public LabelImage(ImageIcon icon) {
			super.setIcon(icon);
		}

		private AlphaComposite cmp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1);
		private float alpha;

		public void setAlpha(float alpha) {
			this.alpha = alpha;
			if (isVisible())
				paintImmediately(getBounds());
		}

		@Override
		protected void paintComponent(Graphics g) {
			Graphics2D g2d = (Graphics2D) g;
			g2d.setComposite(cmp.derive(alpha));
			super.paintComponent(g2d);

		}
	}


